﻿using System;



namespace ScriptEase
{
    /// <summary>
    /// Search a file by its filename (incl. extension) 
    /// in the local script directory structure.
    /// </summary>
    internal class AutoMap : IWorkspaceMapper
    {
        private Workspace _workspace;


        public void Initialize(Workspace workspace)
        {
            _workspace = workspace;
        }

        public string GetFilePath(WebResource webResource)
        {
            throw new NotImplementedException();
            return Workspace.GetFullPathExists(webResource.Name, _workspace.WebResourcesBasePath);

            // Guessing filename
            // This works fine as long as 
            //  a) the fileName is unique in the script directory.
            //      Otherwise an exception is thrown

            //if (!allowGuessing) 
            /* guessing
            string fileName = Path.GetFileName(relativePath);
            if (string.IsNullOrEmpty(fileName))
            {
                Trace.Default.Warn("Cannot get filename from relative path {0}", relativePath);
                return null;
            }


            string[] files = Directory.GetFiles(Workspace.WebResourcesBasePath, fileName, SearchOption.AllDirectories);
            if( files.Length > 1)
                throw new ApplicationException(string.Format("ScriptEase found {0} files named {1}. Guessing failed!", files.Length, fileName));
            
            //
            // ScriptEase has guessed a file!!
            //
            Trace.Default.Warn("The expected file '{0}' does not exist! ScriptEase is guessing '{1}' is the correct file!", relativePath, Workspace.GetRelativePath( files[0]));
            return files.Length ==1 ? files[0] : null;
             */
        }
    }
}